<template>
	<view class="wrap">


		<view class="box-detail">
			<view class="box-detail-header">
				<text class="name">{{pageData[fields.name]}}</text>
				<text class="date">{{pageData[fields.date]}}</text>
			</view>

			<view class="box-detail-content">
				<view class="box-detail-content-row" v-for="item,index in fields.columns" :key="index">
					<text class="row-title">{{item.title}}</text>
					<text class="row-content">{{pageData[item.dataKey] || ''}}</text>
				</view>
			</view>
			<!-- <view class="bar-contact">
				联系人
			</view>
			<view class="box-detail-content border" v-show="contactData.length == 0">
				无
			</view> -->
			<view class="box-detail-content border" v-for="item,index in contactData" :key="index">
				<view class="box-detail-content-row">
					<text class="row-title mag">联系人</text>
					<text class="row-content mag">{{item.CONTACT || ''}}</text>
				</view>
				<view class="box-detail-content-row">
					<text class="row-title mag">联系方式</text>
					<text class="row-content mag">{{item.CONTACT_NUMBER || ''}}</text>
				</view>
				<view class="box-detail-content-row">
					<text class="row-title mag">职务</text>
					<text class="row-content mag">{{item.POST || ''}}</text>
				</view>
			</view>
			<view class="box-attach">
				<view class="box-attach-row" v-for="item,index in attachData" :key="index" @tap="openFile"
					:data-url="item.url">
					<image src="../../../static/images/icon_enclosure.png" mode="widthFix" class="box-attach-icon">
					</image>
					<text class="box-attach-name">{{item.fileShowName}}</text>
				</view>
			</view>
			<view class="box-attach" v-show="code === 'busExhibition'">
				<view class="box-attach-row">
					<text class="box-attach-name1">展会材料</text>
					<image src="../../../static/images/icon_enclosure.png" mode="widthFix" class="box-attach-icon">
					</image>
					<view>
						<view class="box-attach-name" @tap="openFile" :data-url="item.url"
							v-for="item,index in attach1">
							{{item.fileShowName}}
						</view>
					</view>

				</view>
				<view class="box-attach-row" v-show="code === 'busExhibition'" @tap="openFile" :data-url="attach2.url">
					<text class="box-attach-name1">展会成果</text>
					<image src="../../../static/images/icon_enclosure.png" mode="widthFix" class="box-attach-icon">
					</image>
					<view>
						<view class="box-attach-name" @tap="openFile" :data-url="item.url"
							v-for="item,index in attach2">
							{{item.fileShowName}}
						</view>
					</view>

				</view>
			</view>
			<mix-fixed-bar @leftEvent="handleEdit" @rightEvent="handleDelete" barType="1">
			</mix-fixed-bar>
		</view>
	</view>

</template>

<script>
	import mixFixedBar from '../../../components/mix-fixe-bar.vue';
	export default {
		components: {
			mixFixedBar
		},
		data() {
			return {
				pageData: {},
				contactData: [],
				attachData: [],
				date: '2020/12/20',
				dataKey: '',
				fields: {},
				code: '',
				attach1: {

				},
				attach2: {

				}
			}
		},
		methods: {
			handleEdit() {
				console.log(this.code)
				console.log(this.dataKey)
				const path = `../edit/${this.code}?code=${this.code}&dataKey=${this.dataKey}`
				console.log('path', path)
				uni.navigateTo({
					url: path
				})

			},
			handleDelete() {
				console.log('delete')
				uni.showModal({
					title: "确认删除吗"
				})
			},
			formatDetail(code) {
				switch (code) {
					case 'busEnterprise':
						this.fields = {
							name: 'NAME',
							date: 'CREATE_TIME',
							person: 'MANAGER',
							columns: [{
									title: '对接企业性质',
									dataKey: 'DJQYXZ'
								},
								{
									title: '地区',
									dataKey: 'DIST'
								},
								{
									title: '企业规模',
									dataKey: 'COMPANY_SIZE'
								},
								{
									title: '行业类别',
									dataKey: 'industry'
								},
								{
									title: '企业性质',
									dataKey: 'NATURE'
								},
								{
									title: '企业网址',
									dataKey: 'WEBSITE'
								},
								{
									title: '注册地址',
									dataKey: 'ZC_ADDRESS'
								},
								{
									title: '总部地址',
									dataKey: 'HEAD_ADDRESS'
								},
								{
									title: '通讯地址',
									dataKey: 'TX_ADDRESS'
								},
								{
									title: '企业邮箱',
									dataKey: 'EMAIL'
								},
								{
									title: '经营范围',
									dataKey: 'BUSINESS_SCOPE'
								},
								{
									title: '企业简介',
									dataKey: 'COMPANY_PROFILE'
								},
								{
									title: '项目需求',
									dataKey: 'PROJ_DEMAND'
								},
								{
									title: '项目分析',
									dataKey: 'PROJ_ANALYSIS'
								},
							]
						}

						break;
					case 'busInvestor':
						this.fields = {
							name: 'NAME',
							date: 'CREATE_TIME',
							person: 'MANAGER',
							columns: [{
									title: '投资方主体',
									dataKey: 'INVESTORS_BODY'
								},
								{
									title: '投资方类型',
									dataKey: 'TYPE'
								},
								{
									title: '企业性质',
									dataKey: 'NATURE'
								},
								{
									title: '投资领域',
									dataKey: 'INVESTORS_INDUSTRY'
								},
								{
									title: '注册地址',
									dataKey: 'ZC_ADDRESS'
								},
								{
									title: '总部地址',
									dataKey: 'HEAD_ADDRESS'
								},

								{
									title: '企业邮箱',
									dataKey: 'EMAIL'
								},
								{
									title: '企业规模',
									dataKey: 'COMPANY_SIZE'
								},
								{
									title: '企业网址',
									dataKey: 'WEBSITE'
								},
								{
									title: '经营范围',
									dataKey: 'BUSINESS_SCOPE'
								},
								{
									title: '投资方简介',
									dataKey: 'COMPANY_PROFILE'
								},
								{
									title: '跟进人',
									dataKey: 'MANAGER'
								}
							]
						}
						break;
					case 'busOrg':
						this.fields = {
							name: 'NAME',
							date: 'CREATE_TIME',
							person: 'MANAGER',
							columns: [{
									title: '机构类型',
									dataKey: 'TYPE'
								},
								{
									title: '会员企业数',
									dataKey: 'MEMBER_COUNT'
								},
								{
									title: '负责人',
									dataKey: 'OPERATOR'
								},
								{
									title: '负责人职位',
									dataKey: 'OPERATOR_POSITION'
								},
								{
									title: '通讯地址',
									dataKey: 'TX_ADDRESS'
								},
								{
									title: '邮箱',
									dataKey: 'EMAIL'
								},
								{
									title: '机构简介',
									dataKey: 'COMPANY_PROFILE'
								},
								{
									title: '跟进人',
									dataKey: 'MANAGER'
								}
							]
						}

						break;

					case 'busExhibition':

						this.fields = {
							name: 'NAME',
							date: 'START_DATE',
							person: 'MANAGER',
							columns: [{
									title: '行业类别',
									dataKey: 'extIndustry'
								},
								{
									title: '地点',
									dataKey: 'PLACE'
								},
								{
									title: '主办单位',
									dataKey: 'ORGANIZERS'
								},
								{
									title: '联系方式',
									dataKey: 'LINK_TEL'
								},
								{
									title: '邮箱',
									dataKey: 'EMAIL'
								},
								{
									title: '参展简介',
									dataKey: 'REMARK'
								},
								{
									title: '跟进人',
									dataKey: 'MANAGER'
								}
							]
						}
						break;
					case 'busTarget':
						this.fields = {
							name: 'NAME',
							date: 'START_DATE',
							person: 'MANAGER',
							columns: [{
									title: '企业类型',
									dataKey: 'ENTERPRISE_TYPE'
								},
								{
									title: '对接企业性质',
									dataKey: 'DJQYXZ'
								},
								{
									title: '企业规模',
									dataKey: 'COMPANY_SIZE'
								},
								{
									title: '行业类别',
									dataKey: 'industry'
								},
								{
									title: '企业性质',
									dataKey: 'NATURE'
								},
								{
									title: '企业网址',
									dataKey: 'WEBSITE'
								},
								{
									title: '注册地址',
									dataKey: 'ZC_ADDRESS'
								},
								{
									title: '总部地址',
									dataKey: 'HEAD_ADDRESS'
								},
								{
									title: '通讯地址',
									dataKey: 'TX_ADDRESS'
								},
								{
									title: '企业邮箱',
									dataKey: 'EMAIL'
								},
								{
									title: '经营范围',
									dataKey: 'BUSINESS_SCOPE'
								},
								{
									title: '企业简介',
									dataKey: 'COMPANY_PROFILE'
								},
								{
									title: '项目需求',
									dataKey: 'PROJ_DEMAND'
								},
								{
									title: '项目分析',
									dataKey: 'PROJ_ANALYSIS'
								},
							]
						}
						break
					default:
						break;
				}
			},
			openFile(e) {
				const url = e.currentTarget.dataset.url

				this.$util.openFile(url)
			},
			async getDetai() {
				uni.showLoading({

				})
				const ret = await this.$req({
					url: `bus/projmanage/filter.do`,
					data: {
						moduleId: 'busProjManage'
					}
				})
				let personData = []
				if (ret.data.success) {
					personData = ret.data.attributes.zdyDataSource.personDataSourceManage ?
						ret.data.attributes.zdyDataSource.personDataSourceManage : [];
				}
				const dicData = JSON.parse(uni.getStorageSync('dicData'));
				const res = await this.$req({
					url: `info/${this.code}/view.do?dataKey=${this.dataKey}`,
					data: {}
				})
				uni.hideLoading()
				if (res.data.success) {
					const data = {
						...res.data.attributes
					}
					const pageData = {
						...data.model
					}
					//跟进入
					pageData.MANAGER = pageData.MANAGER ? this.$util.queryPersonName(pageData.MANAGER, personData) : ''
					pageData.CREATE_TIME = pageData.CREATE_TIME ? pageData.CREATE_TIME.split(' ')[0] : ''
					//行业类别
					pageData.industry = pageData.INDUSTRY ? this.$util.queryDicName(dicData, 'inve_field',
						pageData.INDUSTRY) : ''
					//对接企业性质
					pageData.DJQYXZ = pageData.DJQYXZ ? this.$util.queryDicName(dicData, 'djqyxz', pageData
						.DJQYXZ) : ''
					//企业规模e nt_scale
					pageData.COMPANY_SIZE = pageData.COMPANY_SIZE ? this.$util.queryDicName(dicData, 'ent_scale',
						pageData.COMPANY_SIZE) : ''
					//企业性质
					pageData.NATURE = pageData.NATURE ? this.$util.queryDicName(dicData, 'dwxz', pageData
						.NATURE) : ''
					//投资方类型
					pageData.TYPE = pageData.TYPE ? this.$util.queryDicName(dicData, 'inve_type', pageData.TYPE) :
						''
					//投资方主体
					pageData.INVESTORS_BODY = pageData.INVESTORS_BODY ? this.$util.queryDicName(dicData,
						'inve_theme', pageData.INVESTORS_BODY) : ''
					//投资领域INVESTORS_INDUSTRY
					pageData.INVESTORS_INDUSTRY = pageData.INVESTORS_INDUSTRY ? this.$util.queryDicName(dicData,
						'inve_field', pageData.INVESTORS_INDUSTRY) : ''
					//展会信息行业类别多选

					pageData.extIndustry = pageData.INDUSTRY ? this.$util.queryDicNameMulti(dicData, 'inve_field',
						pageData.INDUSTRY) : ''
					//企业类型
					pageData.ENTERPRISE_TYPE = pageData.ENTERPRISE_TYPE ? this.$util.queryDicName(dicData,
						'targetType', pageData.ENTERPRISE_TYPE) : ''
					if (data.dataGrid.telephone_view) {
						this.contactData = data.dataGrid.telephone_view.datas
					}
					if (data.fileList['PPP_T_BUS_ENTERPRISE_INFO.xgfj']) {
						this.attachData = data.fileList['PPP_T_BUS_ENTERPRISE_INFO.xgfj'].fileList
					}
					this.pageData = pageData;
					//展会成果
					if (this.code === 'busExhibition' && data.fileList['PPP_T_BUS_EXHIBITION_INFO.zhcg']) {
						this.attach2 = data.fileList['PPP_T_BUS_EXHIBITION_INFO.zhcg'].fileList
					} //展会材料
					if (this.code === 'busExhibition' && data.fileList['PPP_T_BUS_EXHIBITION_INFO.zhcl']) {
						this.attach1 = data.fileList['PPP_T_BUS_EXHIBITION_INFO.zhcl'].fileList
					}
					//地区
					pageData.DIST = res.data.attributes.zdyDataSource.provinceFistAndSecondAndThridDataManage.filter(item=>{
						return item.CODE == pageData.DISTCODE
					})[0].CODE_NAME
					console.log('pageData.DISTCODE',pageData.DISTCODE)
					console.log('pageData.DIST ',pageData.DIST )
				} else {
					uni.showToast({
						title: res.data.messages[0].content
					})
				}
			}
		},
		onLoad(options) {
			console.log('options', options)
			this.code = options.code
			this.dataKey = options.dataKey
			this.formatDetail(options.code)
			this.getDetai()
			uni.setNavigationBarTitle({
				title: options.name
			})
		},
		onShow() {
			uni.$on("refreshDetail", res => {
				this.getDetai()
				uni.$off('refreshDetail');
			})
		},
		onShareAppMessage() {
			return {
				imageUrl: 'https://www.szaez.com/sck/share.jpg?v=' + new Date().getTime(),
				path: '/pages/setionManerge/detail/detail?code=' + this.code + '&name=' + this.name + '&dataKey=' + this
					.dataKey
			}
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		padding-bottom: 60rpx;
	}

	page {
		padding-bottom: 20rpx;
	}

	.box-detail {
		background-color: #ffffff;
		border-radius: 20px;
		margin: 20rpx;
		padding: 26rpx 30rpx 50rpx 30rpx;
	}


	.box-detail-header {
		display: flex;
		justify-content: space-between;
		margin-bottom: 8rpx;

		.name {
			font-size: 30rpx;
			color: #414a5d;
			font-weight: bold;
		}

		.date {
			font-size: 26rpx;
			color: #9a9a9a;
		}
	}

	.box-net {
		font-size: 26rpx;
		color: #0099cc;
	}

	.box-detail-content {
		margin-top: 24rpx;

		&.border {
			border-bottom: 1px solid #e8f0f2;
		}
	}

	.box-detail-content-row {
		display: flex;
		justify-content: space-between;
		margin-bottom: 30rpx;

		.row-title {
			font-size: 26rpx;
			color: #9a9a9a;
			text-align: left;
			flex-shrink: 0;
			width: 120rpx;
			margin-right: 10rpx;

			&.mag {
				margin-left: 18rpx;
			}
		}

		.row-content {
			font-size: 26rpx;
			color: #414a5d;
			word-wrap: break-word;
			word-break: break-all;
			flex: 1;
			text-align: right;

			&.mag {
				margin-right: 18rpx;
			}
		}
	}

	.bar-contact {
		background-color: #0099cc;
		border-radius: 10px;
		height: 40rpx;
		line-height: 40rpx;
		padding-left: 18rpx;
		color: #FFFFFF;
		font-size: 24rpx;

	}

	.box-attach {
		margin-top: 20rpx;
	}

	.box-attach-row {
		display: flex;
		align-items: center;
		padding: 0 18rpx;
		margin-bottom: 10rpx;

		.box-attach-icon {
			width: 34rpx;
			margin-right: 30rpx;
			flex-shrink: 0;
		}

		.box-attach-name {
			word-wrap: break-word;
			word-break: break-all;
			white-space: pre-line;
			font-size: 26rpx;
			color: #0099cc;
			padding-right: 10px;
		}

		.box-attach-name1 {
			font-size: 26rpx;
			color: #0099cc;
			padding-right: 10px;
			width: 65px;
			flex-shrink: 0;
		}
	}
</style>
